<?php


namespace Tbf\Bundle\TbfBundle\Exception;


use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Tbf\Component\Exception\ExceptionFunction;

/**
 * symfony的那个log信息不足...
 */
class ExceptionLoggerListener implements EventSubscriberInterface{
    public function __construct(LoggerInterface $logger = null)
    {
        $this->logger = $logger;
    }
    public function onException(GetResponseForExceptionEvent $event){
        $e = $event->getException();
        $this->logger->error('TbfBundle\Exception Uncaught PHP Exception',
            ExceptionFunction::exceptionToArray($e)
        );
    }
    public static function getSubscribedEvents()
    {
        return array(KernelEvents::EXCEPTION => array('onException',-127));
    }
}